package cn.iocoder.yudao.module.wine.controller.admin.supplyorderlog;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wine.controller.admin.supplyorderlog.vo.*;
import cn.iocoder.yudao.module.wine.dal.dataobject.supplyorderlog.SupplyOrderLogDO;
import cn.iocoder.yudao.module.wine.service.supplyorderlog.SupplyOrderLogService;

@Tag(name = "管理后台 - 供求订单日志")
@RestController
@RequestMapping("/wine/supply-order-log")
@Validated
public class SupplyOrderLogController {

    @Resource
    private SupplyOrderLogService supplyOrderLogService;

    @PostMapping("/create")
    @Operation(summary = "创建供求订单日志")
    @PreAuthorize("@ss.hasPermission('wine:supply-order-log:create')")
    public CommonResult<Long> createSupplyOrderLog(@Valid @RequestBody SupplyOrderLogSaveReqVO createReqVO) {
        return success(supplyOrderLogService.createSupplyOrderLog(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新供求订单日志")
    @PreAuthorize("@ss.hasPermission('wine:supply-order-log:update')")
    public CommonResult<Boolean> updateSupplyOrderLog(@Valid @RequestBody SupplyOrderLogSaveReqVO updateReqVO) {
        supplyOrderLogService.updateSupplyOrderLog(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除供求订单日志")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('wine:supply-order-log:delete')")
    public CommonResult<Boolean> deleteSupplyOrderLog(@RequestParam("id") Long id) {
        supplyOrderLogService.deleteSupplyOrderLog(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得供求订单日志")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('wine:supply-order-log:query')")
    public CommonResult<SupplyOrderLogRespVO> getSupplyOrderLog(@RequestParam("id") Long id) {
        SupplyOrderLogDO supplyOrderLog = supplyOrderLogService.getSupplyOrderLog(id);
        return success(BeanUtils.toBean(supplyOrderLog, SupplyOrderLogRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得供求订单日志分页")
    @PreAuthorize("@ss.hasPermission('wine:supply-order-log:query')")
    public CommonResult<PageResult<SupplyOrderLogRespVO>> getSupplyOrderLogPage(@Valid SupplyOrderLogPageReqVO pageReqVO) {
        PageResult<SupplyOrderLogRespVO> pageResult = supplyOrderLogService.getSupplyOrderLogPage(pageReqVO);
        return success(pageResult);
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出供求订单日志 Excel")
//    @PreAuthorize("@ss.hasPermission('wine:supply-order-log:export')")
//    @OperateLog(type = EXPORT)
//    public void exportSupplyOrderLogExcel(@Valid SupplyOrderLogPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<SupplyOrderLogDO> list = supplyOrderLogService.getSupplyOrderLogPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "供求订单日志.xls", "数据", SupplyOrderLogRespVO.class,
//                        BeanUtils.toBean(list, SupplyOrderLogRespVO.class));
//    }

}
